package douaPahare.operator;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

import douaPahare.container.Stare;


public class Umplere2 extends JButton implements Operator {
	
	private JPanel panel;
	
	public Umplere2(String nume,JPanel p) {
		super(nume);
		panel = p;
	}

	public void executa() throws Exception {
	    if(evaluare(Stare.getStareStatic()))
	    	Stare.setStareStatic(actiune(Stare.getStareStatic()));
		else throw new Exception("Nu se poate umple al doilea pahar!");
	}
	
	public boolean evaluare(Stare st) {
		if(st.getY() == 4) 
			return false;
		else return true;
	}
	
	public Stare actiune(Stare st) {
		final JProgressBar p = (JProgressBar)panel.getComponent(2);
		p.setValue(4);
		return new Stare(st.getX(),4);
	}
	
	public Stare actiune2(Stare st) {
		return new Stare(st.getX(),4);
	}

}
